package com.zxx.coolweather._wuguan2;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.nohttp.Headers;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.RestRequest;
import com.yanzhenjie.nohttp.rest.StringRequest;

/**
 * 返回WeatherBean类
 *
 * @author zxx on 2022/1/12
 */
public class RequestWeatherBean extends RestRequest<WeatherBean> {

    public RequestWeatherBean(String url) {
        super(url);
    }

    public RequestWeatherBean(String url, RequestMethod requestMethod) {
        super(url, requestMethod);
    }

    @Override
    public WeatherBean parseResponse(Headers responseHeaders, byte[] responseBody) throws Exception {
        WeatherBean bean;
        String str = StringRequest.parseResponseString(responseHeaders, responseBody);
        try {
            bean = JSON.parseObject(str, WeatherBean.class);
        } catch (Exception e) {
            bean = new WeatherBean();
        }
        return bean;
    }
}
